package main

import "fmt"

//结构体嵌套
//在golang，结构体嵌套方式有两种

type person struct {
	Gender string
	Name   string
}

func (p *person) printInfo() {
	fmt.Println(p.Name, p.Gender)
}

//第一种显示嵌套
type student struct {
	Ps    *person
	Sno   int
	Class string
}

//第二种隐式嵌套
type student1 struct {
	*person
	Sno   int
	Class string
}

func main() {
	s1 := &student{
		Ps: &person{
			Gender: "male",
			Name:   "zhangsan",
		},
		Sno:   1,
		Class: "三年二班",
	}
	s1.Ps.printInfo()
	fmt.Println(s1.Ps, s1.Ps.Name, s1)

	s2 := &student1{
		person: &person{
			Gender: "female",
			Name:   "Alice",
		},
		Sno:   15,
		Class: "三年一班",
	}
	fmt.Println(s2.person, s2.Name, s2) //s2.Name = s2.person.Name
	s2.printInfo()
}
